package gauss;

import java.io.File;
import java.text.DecimalFormat;


import org.junit.Test;

import common.IMS_CSV_File;
import common.ImageMethods;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.*;


public class TestForkJoinFastGauss {

	@Test
	public void validate() {
	
		File folder = new File("E:/_IPHEx CBF/ims_files/");
		File[] listFiles = folder.listFiles();
		int max = 20;
		int i = 0;
		long totalRuntime1 = 0;
		long totalRuntime2 = 0;
		for (File file : listFiles) {
			i++;
			IMS_CSV_File imsFile = new IMS_CSV_File(file);
			double[][] sourceMap = imsFile.getMap();
			
			long startTime1 = System.currentTimeMillis();
			double[][] actual = ForkJoinFastGauss.forkJoinFastGauss(sourceMap);
			long endTime1 = System.currentTimeMillis();
			long runtime1 = endTime1 - startTime1;
			totalRuntime1 += runtime1;
			System.out.print("Fast filter avarage runtime " + totalRuntime1/i + " milliseconds  ");
			
			long startTime2 = System.currentTimeMillis();
			double[][] expected = ImageMethods.filterGauss2(sourceMap);
			long endTime2 = System.currentTimeMillis();
			long runtime2 = endTime2 - startTime2;
			totalRuntime2 += runtime2;
			System.out.print("Normal filter Avarage runtime " + totalRuntime2/i + " milliseconds. (avaraged "+i+") ");
			
			
			double ratio = (double)totalRuntime1/(double)totalRuntime2;
			System.out.print(new DecimalFormat("#.##").format(ratio)+"%");
			
			assertNotNull(expected);
			assertNotNull(actual);
			assertArrayEquals(expected, actual);
			System.out.println(" -> result validated");
		
			if(i >= max) break;
		}
		System.out.println(i+" Files tested");
		
//		IMS_CSV_File imsFile = new IMS_CSV_File(new File("E:/_IPHEx CBF/ims_files/NI24_0909171332_ims.csv"));
//		double[][] sourceMap = imsFile.getMap();
//		
//		double[][] expected = ImageMethods.filterMedian(sourceMap, 5);		
//		double[][] actual = ForkJoinFastMedian.forkJoinFastMedian(sourceMap);
//
//		
//		assertArrayEquals(expected, actual);

	}
	
}
